-
Notifications
You must be signed in to change notification settings - Fork 393
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: add opf-load-once capability on js and css resources #19825
Conversation
protected readonly CORS_DEFAULT_VALUE = 'anonymous'; | ||
protected readonly OPF_RESOURCE_LOAD_ONCE_ATTR_KEY = 'opf-load-once'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use for consistency: OPF_RESOURCE_LOAD_ONCE_ATTRIBUTE_KEY
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also would be good in my opinion to prefix all custom html attributes with "data-".
https://www.w3schools.com/tags/att_data-.asp
Can we change attribute key to: data-opf-load-once
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to add 'data-' prefix:
'opf-load-once' is never added as attribute key, it is just a variable that decides if we add 'data-opf-resource' attribute or not.
To sum-up, we receive it in attributes property from server but using it as a flag in this service.
|
||
protected embedStyles(embedOptions: { | ||
attributes?: OpfKeyValueMap[]; | ||
attributes?: { [key: string]: string }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it new type different than OpfKeyValueMap[]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it was set as 'any'.
OpfKeyValueMap is {key:string,value:string}, we receive the list in this format from resource object (resource.attributes).
We perform a conversion to [key: string]: string to make handling easier and have same type as attributes in ScriptLoader service
@@ -82,31 +103,21 @@ export class OpfResourceLoaderService { | |||
*/ | |||
protected loadScript(resource: OpfDynamicScriptResource): Promise<void> { | |||
return new Promise((resolve, reject) => { | |||
const attributes: any = { | |||
const attributes: { [key: string]: string } = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we create type for it in a model if we cannot use: OpfKeyValueMap
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mentioned above, we need both:
OpfKeyValueMap is the original format (resource.attributes received from server)
{ [key: string]: string } is format needed for ScriptLoaderService
Thus a conversion is needed.
integration-libs/opf/base/root/services/opf-resource-loader.service.ts
Outdated
Show resolved
Hide resolved
spartacus Run #46637
Run Properties:
|
Project |
spartacus
|
Branch Review |
feature/CXSPA-8883_v2
|
Run status |
Passed #46637
|
Run duration | 03m 50s |
Commit |
381a9f9b09 ℹ️: Merge caab9fda3dcef0349f31641a43f068ca8c0c7735 into 2b9e915b7a0bf2fe0a1fec5565fd...
|
Committer | Florent Letendre |
View all properties for this run ↗︎ |
Test results | |
---|---|
Failures |
0
|
Flaky |
3
|
Pending |
2
|
Skipped |
0
|
Passing |
125
|
View all changes introduced in this branch ↗︎ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.